#include <bits/stdc++.h>

using namespace std;

const int MAXN = 5010;
const int MAXQ = 1e6+10;

int even[MAXN],odd[MAXN],n,m,q,h[MAXN],cnt;
bool ans[MAXQ];

struct edge{int v,nxt;}e[MAXN<<1];
struct quest{int num,v,dis;};

vector<quest> ques[MAXN];
void link(int x,int y){e[++cnt] = (edge){y,h[x]};h[x] = cnt;}
void dijk(int s){
	memset(even,0x3f,(n+2)<<2);memset(odd,0x3f,(n+2)<<2);
	queue<pair<int,int> >q;
	for(int i = h[s];i;i = e[i].nxt){int y = e[i].v;odd[y] = 1;q.push(make_pair(-1,y));}
	while(q.size()){
		int x = q.front().second,d = q.front().first;q.pop();d=-d;
		for(int i = h[x];i;i = e[i].nxt){
			int y = e[i].v; if(even[y] > d+1 && (d & 1)){even[y] = d+1;q.push(make_pair(-even[y],y));}
			if(odd[y] > d+1 && !(d&1)){odd[y] = d+1;q.push(make_pair(-odd[y],y));}
		}
	}
}
		
int main (){
	scanf("%d %d %d",&n,&m,&q);
	for(int i = 1;i <= m;i++){int x,y;scanf("%d %d",&x,&y);link(x,y);link(y,x);}
	for(int i = 1;i <= q;i++){quest x;int fro;scanf("%d %d %d",&fro,&x.v,&x.dis);x.num = i;ques[fro].push_back(x);}
	for(int i = 1;i <= n;i++){
		if(!ques[i].size()) continue;
		dijk(i);for(int j = 0;j < ques[i].size();j++){quest x=ques[i][j];if((odd[x.v] <= x.dis && x.dis & 1) || (even[x.v] <= x.dis && !(x.dis&1))) ans[x.num] = 1;}
	}
	for(int i = 1;i <= q;i++) if(ans[i]) puts("TAK");else puts("NIE");return 0;		
}
